package com.boat.framework.common.thread;

import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;

import com.boat.framework.common.constant.GolbalConsts;
import com.boat.framework.common.util.SpringUtils;

import lombok.extern.slf4j.Slf4j;

/**
 * 线程池工具
 * 
 * @author 周江
 *
 */
@Slf4j
public class ThreadPool {
	private static ThreadPool instance = new ThreadPool();

	public static ThreadPool instance() {
		return instance;
	}

	/**
	 * 异步执行流程
	 * 
	 * @param command
	 */
	public void runProcess(Runnable command) {
		Executor executor = SpringUtils.getBean(GolbalConsts.ThreadPool.EXECUTOR_PROCESS);
		if (executor != null) {
			executor.execute(command);
		} else {
			log.warn("未找到指定线程池，命令未被提交");
		}
	}

	/**
	 * 获得定时任务线程池
	 * 
	 * @return
	 */
	public ScheduledExecutorService getSchedule() {
		return SpringUtils.getBean(GolbalConsts.ThreadPool.EXECUTOR_SCHEDULED);
	}
}